#pragma once
#include <iostream>
#include <pthread.h>

class Mutex
{
public:
    Mutex(pthread_mutex_t* pmutex)
        :_pmutex(pmutex)
    {}

    ~Mutex()
    {}

    void Lock()
    {
        //上锁
        pthread_mutex_lock(_pmutex);
    }

    void UnLock()
    {
        //解锁
        pthread_mutex_unlock(_pmutex);
    }

private:
    pthread_mutex_t *_pmutex;   //锁
};

class Guard : public Mutex
{
public:
    Guard(pthread_mutex_t* pmutex)
        :Mutex(pmutex)
    {
        Lock();
    }

    ~Guard()
    {
        UnLock();
    }
};